<?php
/*
 * @美潮风
 * @功能说明：支付统一入口
 * @更新说明：暂无更新
 * @文件名 Ping.class.php
 * @编码 UTF-8
 * @创建时间 2016-1-22 下午6:13:52
 * @创建人 XING
 */
namespace service\ping;
require SCRIPT_ROOT . '/../../library/ping/init.php';

class Ping
{
    const appkey = 'sk_live_eHeHuLTOWX1GeLSSe9mP0eH4';
	//const appkey = 'sk_test_XrPmjDqH8SaTSOen1008av5K';
    const appid  = 'app_iHyH8SO4OyLOS0yv';
    const appid2  = 'app_iHyH8SO4OyLOS0yv';

    /*
     * 支付入口
     * @date: 2015-6-22 下午2:17:48
     * @editor: XING
     */
    public function payinit($order, $amount, $payChannel, $sub = '商城支付订单', $body = '订单付款支付') {
        \Pingpp\Pingpp::setApiKey(self::appkey);
        $data = \Pingpp\Charge::create(array(
            'order_no'  => $order,
            'amount'    => $amount * 100,
            'app'       => array('id' => I('post.tag') == 'android' && $payChannel == 'wx' ? self::appid2 : self::appid),
            'channel'   => $payChannel,
            'currency'  => 'cny',
            'client_ip' => $_SERVER['SERVER_ADDR'],
            'subject'   => $sub,
            'body'      => $body,
            'metadata'  => array('order_id' => $order)
        ));

        return $data;
    }

    /*
	 * 美潮风_售后退款入口
	 * @date: 2016-3-31 下午2:05:54
	 * @editor: XING
	 */
    public function payRefund($cid, $order_id, $mon) {
        \Pingpp\Pingpp::setApiKey(self::appkey);
        $ch = \Pingpp\Charge::retrieve($cid);
        $reback = $ch->refunds->create(
            array(
                'amount'      => $mon * 100,
                'description' => $order_id
            )
        );

        return $reback;
    }
}

?>